package io;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;

public class InputStreamReaderTest {
    public static void main(String[] args) {
        readUTF8();
        readGBK();
    }

    private static void readUTF8() {
        try (InputStreamReader isr = new InputStreamReader(new FileInputStream(
                "/Users/luchuan/IdeaProjects/java-test/utf8.txt"), "UTF-8")) {
            final char[] chars = new char[1024];
            int len;
            if ((len = isr.read(chars)) != -1) {
                System.out.println(new String(chars,0,len));
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    private static void readGBK() {
        try (InputStreamReader isr = new InputStreamReader(new FileInputStream(
                "/Users/luchuan/IdeaProjects/java-test/gbk.txt"), "GBK")) {
            final char[] chars = new char[1024];
            int len;
            if ((len = isr.read(chars)) != -1) {
                System.out.println(new String(chars,0,len));
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
